package com.rms.service.impl;

import java.util.List;

import com.rms.domain.CompanyManager;
import com.rms.domain.Hr;
import com.rms.domain.Job;
import com.rms.domain.ResumeJob;
import com.rms.utils.service.BaseService;

public class CompanyManagerServiceImpl extends BaseService implements com.rms.service.CompanyManagerService {

	
	@Override
	public void regist(CompanyManager manager) throws Exception {
		
		if (manager.getPassword() == null || "".equals(String.valueOf(manager.getPassword()))) {
			// 判断密码是否为空
			throw new RuntimeException("密码不能为空!");
		}
		
		if (manager.getPassword().length() < 6 || manager.getPassword().length() > 32) {
			// 判断用户名长度是否符合规则
			throw new RuntimeException("密码必须是6~32位的字母数字!");
		}
		companyManagerDao.save(manager);
	}

	@Override
	public void addHR(Hr hr) throws Exception {
		hrDao.save(hr);
	}

	@Override
	public void deleteHR(int hr_id) throws Exception {
		// TODO Auto-generated method stub
		hrDao.delete(hr_id);
	}

	/* 
	 * 更新简历状态
	 */
	@Override
	public void sendResumeToHR(int hr_id, String[] selectResumeIndex) throws Exception {
		// TODO Auto-generated method stub
		ResumeJob resumeJob;
		int index = 0;
		for (int i = 0; i < selectResumeIndex.length; i++) {
			//t_resume_job的id值
			index = Integer.parseInt(selectResumeIndex[i]);
			//得到ResumeJob
			resumeJob = resumeJobDao.get(index);
			//设置hr参数
			resumeJob.setHrId(hr_id);
			resumeJobDao.update(resumeJob);
		}
	}

	@Override
	public void addJob(Job job) throws Exception {
		jobDao.save(job);
	}

	@Override
	public void updateJob(Job job) throws Exception {
		jobDao.update(job);
		
	}

	

	@Override
	public void deleteJob(int job_id) throws Exception {
		jobDao.delete(job_id);
	}

	@Override
	public List<Hr> findHRByManagerId(int manager_id) throws Exception {
		return companyManagerDao.get(manager_id).getCompany().getHrs();
	}


//	public CompanyManager login(CompanyManager manager, Class<CompanyManager> class1) throws Exception {
//		// TODO Auto-generated method stub
//		return (CompanyManager) super.login(manager, class1);
//	}

	@Override
	public List<Job> findJobByManagerId(int manager_id) throws Exception {
		return companyManagerDao.get(manager_id).getCompany().getJobs();
	}



}
